package com.cqut.forum.aspect.imp;

import java.util.Date;

import javax.annotation.Resource;

import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

import com.cqut.forum.aspect.UserLogAspect;
import com.cqut.forum.entity.User;
import com.cqut.forum.service.UserService;

/**
 * 用户日志切面接口实现类
 * @author yangxun
 */

@Aspect
@Component
public class UserLogAspectImp implements UserLogAspect {
	@Resource
	private UserService userService;
	
	@AfterReturning(returning="re",pointcut="execution(public * com.cqut.forum.service.imp.*.*(..))")
	public void addUserLog(Object re) {
		System.out.println("日志添加成功！");
	}
	@AfterReturning(returning="user",pointcut="execution(public * com.cqut.forum.service.imp.UserServiceImp.login(..))")
	public void updateLastLoginTime(User user) {
		
		if(user != null){
			user.setUserLastLoginTime(new Date());
			user = userService.update(user);
			System.out.println("登录成功！更新最后一次登录时间");
		}
		else{
			System.out.println("登录失败！");
		}
	}
}
